package ttc.sftp.data;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;

import android.R.string;
import android.net.Uri;
import android.util.Log;

public class VFile {
	public enum Status {
		None, Copy, Cut
	};

	private String path;
	private String name;
	private Boolean isDirectory;
	private File file;
	private Status status;
	public boolean check;

	public String getName() {
		return name;
	}

	public Boolean IsDirectory() {
		return isDirectory;
	}

	public String getPath() {
		return path;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public VFile(String path) {
		this.file = new File(path);
		this.name = file.getName();
		this.path = file.getPath();
		this.isDirectory = file.isDirectory();
		this.status = Status.None;
	}

	public List<VFile> getListFiles() {
		FilenameFilter filter = new FilenameFilter() {
			@Override
			public boolean accept(File dir, String filename) {
				File sel = new File(dir, filename);
				// Filters based on whether the file is hidden or not
				return (sel.isFile() || sel.isDirectory()) && !sel.isHidden();
			}
		};
		List<VFile> listFiles = new ArrayList<VFile>();
		File[] files = file.listFiles(filter);
		VFile temp;
		if (files != null)
			for (int i = 0; i < files.length; i++) {
				temp = new VFile(files[i].getPath());
				listFiles.add(temp);
			}
		return listFiles;
	}

	public String GetParent() {
		return file.getParent();
	}

	public Uri getUri() {
		return Uri.fromFile(file);
	}

	public String getExt() {
		String extension = "";
		try {
			extension = path
					.substring(path.lastIndexOf(".") + 1, path.length());
		} catch (Exception e) {
		}
		Log.v("viet", extension);
		return extension;
	}

	public String getFileNameTrim() {
		String filename = file.getName();
		if (filename.length() > 20)
			filename = filename.substring(0, 10)
					+ "..."
					+ filename.substring(filename.length() - 10,
							filename.length());
		return filename;
	}
}
